{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 167,
   "id": "587074a2-d515-4939-b623-5ad3ba2aa494",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from sklearn.model_selection import train_test_split\n",
    "import pickle\n",
    "import xgboost\n",
    "import numpy as np\n",
    "import seaborn as sns\n",
    "from sklearn.ensemble import *\n",
    "from sklearn.tree import DecisionTreeClassifier\n",
    "from sklearn.neural_network import MLPClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "id": "b415f867-f3c6-481e-8b43-52a5f263a775",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   survived  sex  age  fare  embarked  class  alone  age*class\n",
      "0         0    0  1.0     0         0      3      0        3.0\n",
      "1         1    1  2.0     3         1      1      0        2.0\n",
      "2         1    1  1.0     1         0      3      1        3.0\n",
      "3         1    1  2.0     3         0      1      0        2.0\n",
      "4         0    0  2.0     1         0      3      1        6.0 \n",
      "\n",
      "0.01\n",
      "XGBClassifier\n",
      "0.85601 0.77778\n",
      "RandomForestClassifier\n",
      "0.85714 0.77778\n",
      "MLPClassifier\n",
      "0.85714 0.88889\n",
      "__________________________________________________\n",
      "0.15\n",
      "XGBClassifier\n",
      "0.85997 0.79851\n",
      "RandomForestClassifier\n",
      "0.86129 0.80597\n",
      "MLPClassifier\n",
      "0.86129 0.80597\n",
      "__________________________________________________\n",
      "0.5\n",
      "XGBClassifier\n",
      "0.87865 0.78475\n",
      "RandomForestClassifier\n",
      "0.87865 0.78924\n",
      "MLPClassifier\n",
      "0.87865 0.78924\n",
      "__________________________________________________\n"
     ]
    }
   ],
   "source": [
    "dataset = sns.load_dataset(\"titanic\")\n",
    "dataset=dataset.drop('embark_town',axis= 1)\n",
    "dataset = dataset.drop('alive', axis=1)\n",
    "dataset= dataset.drop('who', axis=1)\n",
    "dataset= dataset.drop('adult_male', axis=1)\n",
    "dataset= dataset.drop('pclass', axis=1)\n",
    "dataset= dataset.drop('deck', axis=1)\n",
    "dataset= dataset.drop('parch', axis=1)\n",
    "dataset= dataset.drop('sibsp', axis=1)\n",
    "\n",
    "dataset['age']=dataset['age'].fillna(dataset['age'].mean())\n",
    "dataset['sex'] = dataset['sex'].map( {'female': 1, 'male': 0} ).astype(int)\n",
    "dataset['class'] = dataset['class'].map( {'Third': 3, 'Second': 2, 'First': 1} ).astype(int)\n",
    "dataset['alone'] = dataset['alone'].map( {True: 1, False: 0} ).astype(int)\n",
    "\n",
    "dataset['age_band'] = pd.cut(dataset['age'], 5)\n",
    "dataset.loc[ dataset['age'] <= 16, 'age'] = 0\n",
    "dataset.loc[(dataset['age'] > 16) & (dataset['age'] <= 32), 'age'] = 1\n",
    "dataset.loc[(dataset['age'] > 32) & (dataset['age'] <= 48), 'age'] = 2\n",
    "dataset.loc[(dataset['age'] > 48) & (dataset['age'] <= 64), 'age'] = 3\n",
    "dataset.loc[ dataset['age'] > 64, 'age']\n",
    "dataset = dataset.drop(['age_band'], axis=1)\n",
    "\n",
    "freq_port  = dataset.embarked.dropna().mode()[0]\n",
    "dataset['embarked'] = dataset['embarked'].fillna(freq_port)\n",
    "dataset['embarked'] = dataset['embarked'].map( {'S': 0, 'C': 1, 'Q': 2} ).astype(int)\n",
    "\n",
    "\n",
    "dataset['fare'].fillna(dataset['fare'].dropna().median(), inplace=True)\n",
    "dataset['FareBand'] = pd.qcut(dataset['fare'], 4)\n",
    "dataset.loc[ dataset['fare'] <= 7.91, 'fare'] = 0\n",
    "dataset.loc[(dataset['fare'] > 7.91) & (dataset['fare'] <= 14.454), 'fare'] = 1\n",
    "dataset.loc[(dataset['fare'] > 14.454) & (dataset['fare'] <= 31), 'fare']   = 2\n",
    "dataset.loc[ dataset['fare'] > 31, 'fare'] = 3\n",
    "dataset['fare'] = dataset['fare'].astype(int)\n",
    "dataset = dataset.drop(['FareBand'], axis=1)\n",
    "\n",
    "dataset['age*class'] = dataset.age * dataset['class']\n",
    "\n",
    "\n",
    "dataset.head()\n",
    "\n",
    "X = dataset.drop(\"survived\", axis=1)\n",
    "y = dataset['survived']\n",
    "\n",
    "print(dataset.head(), '\\n')\n",
    "\n",
    "for size in [0.01, 0.15, 0.5]:\n",
    "    print(size)\n",
    "    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=size, random_state=42)\n",
    "    model_xgb = xgboost.XGBClassifier(n_estimators=100, random_state=42).fit(X_train, y_train)\n",
    "\n",
    "    models = (\n",
    "        (xgboost.XGBClassifier, {'n_estimators':100}),\n",
    "        (RandomForestClassifier, {'n_estimators':100}),\n",
    "        (MLPClassifier, {'solver': 'lbfgs', 'alpha': 1e-5, 'max_iter': 50000})\n",
    "    )\n",
    "\n",
    "    for model_class, kwargs in models:\n",
    "        model = model_class(random_state=42, **kwargs).fit(X_train, y_train)\n",
    "        print(model.__class__.__name__)\n",
    "        model_train = round(model.score(X_train, y_train), 5)\n",
    "        model_test = round(model.score(X_test, y_test), 5)\n",
    "        print(model_train, model_test)\n",
    "    \n",
    "    \n",
    "    print(50*\"_\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "id": "d80a29cd-e306-4d06-b9fe-3892399e81a2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "xgboost.sklearn.XGBClassifier"
      ]
     },
     "execution_count": 145,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xgboost.XGBClassifier().__class__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 189,
   "id": "c4677ae0-4cdc-4b4a-af48-10a21403ac0b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   survived  pclass  sex   age  sibsp     fare  embarked  class  adult_male  \\\n",
      "0         0       3    0  22.0      1   7.2500         0      3           1   \n",
      "1         1       1    1  38.0      1  71.2833         1      1           0   \n",
      "2         1       3    1  26.0      0   7.9250         0      3           0   \n",
      "3         1       1    1  35.0      1  53.1000         0      1           0   \n",
      "4         0       3    0  35.0      0   8.0500         0      3           1   \n",
      "\n",
      "   alone  \n",
      "0      0  \n",
      "1      0  \n",
      "2      1  \n",
      "3      0  \n",
      "4      1   \n",
      "\n",
      "0.01\n",
      "XGBClassifier\n",
      "0.85601 0.77778\n",
      "RandomForestClassifier\n",
      "0.89796 0.77778\n",
      "RandomForestClassifier\n",
      "0.98186 1.0\n",
      "__________________________________________________\n",
      "0.15\n",
      "XGBClassifier\n",
      "0.86658 0.83582\n",
      "RandomForestClassifier\n",
      "0.91017 0.79851\n",
      "RandomForestClassifier\n",
      "0.98018 0.81343\n",
      "__________________________________________________\n",
      "0.2\n",
      "XGBClassifier\n",
      "0.87079 0.83799\n",
      "RandomForestClassifier\n",
      "0.90449 0.75419\n",
      "RandomForestClassifier\n",
      "0.98034 0.81006\n",
      "__________________________________________________\n"
     ]
    }
   ],
   "source": [
    "dataset = sns.load_dataset(\"titanic\")\n",
    "dataset=dataset.drop('embark_town',axis= 1)\n",
    "dataset = dataset.drop('alive', axis=1)\n",
    "dataset= dataset.drop('who', axis=1)\n",
    "dataset= dataset.drop('deck', axis=1)\n",
    "dataset= dataset.drop('parch', axis=1)\n",
    "\n",
    "dataset['age']=dataset['age'].fillna(dataset['age'].mean())\n",
    "dataset['sex'] = dataset['sex'].map( {'female': 1, 'male': 0} ).astype(int)\n",
    "dataset['class'] = dataset['class'].map( {'Third': 3, 'Second': 2, 'First': 1} ).astype(int)\n",
    "dataset['alone'] = dataset['alone'].map( {True: 1, False: 0} ).astype(int)\n",
    "\n",
    "# dataset= dataset.drop('adult_male', axis=1)\n",
    "dataset['adult_male'] = dataset['adult_male'].map( {True: 1, False: 0} ).astype(int)\n",
    "\n",
    "freq_port  = dataset.embarked.dropna().mode()[0]\n",
    "dataset['embarked'] = dataset['embarked'].fillna(freq_port)\n",
    "dataset['embarked'] = dataset['embarked'].map( {'S': 0, 'C': 1, 'Q': 2} ).astype(int)\n",
    "\n",
    "dataset.head()\n",
    "\n",
    "X = dataset.drop(\"survived\", axis=1)\n",
    "y = dataset['survived']\n",
    "\n",
    "print(dataset.head(), '\\n')\n",
    "\n",
    "for size in [0.01, 0.15, 0.2,]:\n",
    "    print(size)\n",
    "    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=size, random_state=42)\n",
    "    model_xgb = xgboost.XGBClassifier(n_estimators=100, random_state=42).fit(X_train, y_train)\n",
    "\n",
    "    models = (\n",
    "        (xgboost.XGBClassifier, {'n_estimators':1}),\n",
    "        (RandomForestClassifier, {'n_estimators':1}),\n",
    "        (RandomForestClassifier, {'n_estimators':1, 'bootstrap': False}),\n",
    "        # (MLPClassifier, {'solver': 'lbfgs', 'alpha': 1e-5, 'max_iter': 50000})\n",
    "    )\n",
    "\n",
    "    for model_class, kwargs in models:\n",
    "        model = model_class(random_state=42, **kwargs).fit(X_train, y_train)\n",
    "        print(model.__class__.__name__)\n",
    "        model_train = round(model.score(X_train, y_train), 5)\n",
    "        model_test = round(model.score(X_test, y_test), 5)\n",
    "        print(model_train, model_test)\n",
    "    \n",
    "    \n",
    "    print(50*\"_\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4468d5e1-6a16-4458-8434-1a4bb2eff75d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 190,
   "id": "f0fb9ac7-3edf-4771-b2e9-3f68099a0a52",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)\n"
     ]
    }
   ],
   "source": [
    "from shap import GPUTreeExplainer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 195,
   "id": "c9b7ce80-1add-4e4f-b911-255dd40659c8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cuda extension was not built during install!\n"
     ]
    },
    {
     "ename": "ImportError",
     "evalue": "cannot import name '_cext_gpu' from partially initialized module 'shap' (most likely due to a circular import) (D:\\AMI\\venv\\Lib\\site-packages\\shap\\__init__.py)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mImportError\u001b[0m                               Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[195], line 2\u001b[0m\n\u001b[0;32m      1\u001b[0m e \u001b[38;5;241m=\u001b[39m GPUTreeExplainer(model_xgb)\n\u001b[1;32m----> 2\u001b[0m \u001b[43me\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mshap_values\u001b[49m\u001b[43m(\u001b[49m\u001b[43mX_train\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\AMI\\venv\\Lib\\site-packages\\shap\\explainers\\_gpu_tree.py:107\u001b[0m, in \u001b[0;36mGPUTree.shap_values\u001b[1;34m(self, X, y, tree_limit, approximate, check_additivity, from_call)\u001b[0m\n\u001b[0;32m    104\u001b[0m transform \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mget_transform()\n\u001b[0;32m    106\u001b[0m \u001b[38;5;66;03m# run the core algorithm using the C extension\u001b[39;00m\n\u001b[1;32m--> 107\u001b[0m \u001b[43massert_import\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcext_gpu\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m    108\u001b[0m phi \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mzeros((X\u001b[38;5;241m.\u001b[39mshape[\u001b[38;5;241m0\u001b[39m], X\u001b[38;5;241m.\u001b[39mshape[\u001b[38;5;241m1\u001b[39m] \u001b[38;5;241m+\u001b[39m \u001b[38;5;241m1\u001b[39m, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mnum_outputs))\n\u001b[0;32m    109\u001b[0m _cext_gpu\u001b[38;5;241m.\u001b[39mdense_tree_shap(\n\u001b[0;32m    110\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mchildren_left, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mchildren_right, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mchildren_default,\n\u001b[0;32m    111\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mfeatures, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mthresholds, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mvalues,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    115\u001b[0m     output_transform_codes[transform], \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[0;32m    116\u001b[0m )\n",
      "File \u001b[1;32mD:\\AMI\\venv\\Lib\\site-packages\\shap\\utils\\_general.py:18\u001b[0m, in \u001b[0;36massert_import\u001b[1;34m(package_name)\u001b[0m\n\u001b[0;32m     16\u001b[0m msg,e \u001b[38;5;241m=\u001b[39m import_errors[package_name]\n\u001b[0;32m     17\u001b[0m \u001b[38;5;28mprint\u001b[39m(msg)\n\u001b[1;32m---> 18\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m e\n",
      "    \u001b[1;31m[... skipping hidden 1 frame]\u001b[0m\n",
      "Cell \u001b[1;32mIn[195], line 2\u001b[0m\n\u001b[0;32m      1\u001b[0m e \u001b[38;5;241m=\u001b[39m GPUTreeExplainer(model_xgb)\n\u001b[1;32m----> 2\u001b[0m \u001b[43me\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mshap_values\u001b[49m\u001b[43m(\u001b[49m\u001b[43mX_train\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\AMI\\venv\\Lib\\site-packages\\shap\\explainers\\_gpu_tree.py:107\u001b[0m, in \u001b[0;36mGPUTree.shap_values\u001b[1;34m(self, X, y, tree_limit, approximate, check_additivity, from_call)\u001b[0m\n\u001b[0;32m    104\u001b[0m transform \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mget_transform()\n\u001b[0;32m    106\u001b[0m \u001b[38;5;66;03m# run the core algorithm using the C extension\u001b[39;00m\n\u001b[1;32m--> 107\u001b[0m \u001b[43massert_import\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcext_gpu\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m    108\u001b[0m phi \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mzeros((X\u001b[38;5;241m.\u001b[39mshape[\u001b[38;5;241m0\u001b[39m], X\u001b[38;5;241m.\u001b[39mshape[\u001b[38;5;241m1\u001b[39m] \u001b[38;5;241m+\u001b[39m \u001b[38;5;241m1\u001b[39m, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mnum_outputs))\n\u001b[0;32m    109\u001b[0m _cext_gpu\u001b[38;5;241m.\u001b[39mdense_tree_shap(\n\u001b[0;32m    110\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mchildren_left, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mchildren_right, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mchildren_default,\n\u001b[0;32m    111\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mfeatures, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mthresholds, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mvalues,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    115\u001b[0m     output_transform_codes[transform], \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[0;32m    116\u001b[0m )\n",
      "File \u001b[1;32mD:\\AMI\\venv\\Lib\\site-packages\\shap\\utils\\_general.py:18\u001b[0m, in \u001b[0;36massert_import\u001b[1;34m(package_name)\u001b[0m\n\u001b[0;32m     16\u001b[0m msg,e \u001b[38;5;241m=\u001b[39m import_errors[package_name]\n\u001b[0;32m     17\u001b[0m \u001b[38;5;28mprint\u001b[39m(msg)\n\u001b[1;32m---> 18\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m e\n",
      "    \u001b[1;31m[... skipping hidden 1 frame]\u001b[0m\n",
      "Cell \u001b[1;32mIn[195], line 2\u001b[0m\n\u001b[0;32m      1\u001b[0m e \u001b[38;5;241m=\u001b[39m GPUTreeExplainer(model_xgb)\n\u001b[1;32m----> 2\u001b[0m \u001b[43me\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mshap_values\u001b[49m\u001b[43m(\u001b[49m\u001b[43mX_train\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\AMI\\venv\\Lib\\site-packages\\shap\\explainers\\_gpu_tree.py:107\u001b[0m, in \u001b[0;36mGPUTree.shap_values\u001b[1;34m(self, X, y, tree_limit, approximate, check_additivity, from_call)\u001b[0m\n\u001b[0;32m    104\u001b[0m transform \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mget_transform()\n\u001b[0;32m    106\u001b[0m \u001b[38;5;66;03m# run the core algorithm using the C extension\u001b[39;00m\n\u001b[1;32m--> 107\u001b[0m \u001b[43massert_import\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcext_gpu\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m    108\u001b[0m phi \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mzeros((X\u001b[38;5;241m.\u001b[39mshape[\u001b[38;5;241m0\u001b[39m], X\u001b[38;5;241m.\u001b[39mshape[\u001b[38;5;241m1\u001b[39m] \u001b[38;5;241m+\u001b[39m \u001b[38;5;241m1\u001b[39m, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mnum_outputs))\n\u001b[0;32m    109\u001b[0m _cext_gpu\u001b[38;5;241m.\u001b[39mdense_tree_shap(\n\u001b[0;32m    110\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mchildren_left, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mchildren_right, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mchildren_default,\n\u001b[0;32m    111\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mfeatures, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mthresholds, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel\u001b[38;5;241m.\u001b[39mvalues,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    115\u001b[0m     output_transform_codes[transform], \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[0;32m    116\u001b[0m )\n",
      "File \u001b[1;32mD:\\AMI\\venv\\Lib\\site-packages\\shap\\utils\\_general.py:18\u001b[0m, in \u001b[0;36massert_import\u001b[1;34m(package_name)\u001b[0m\n\u001b[0;32m     16\u001b[0m msg,e \u001b[38;5;241m=\u001b[39m import_errors[package_name]\n\u001b[0;32m     17\u001b[0m \u001b[38;5;28mprint\u001b[39m(msg)\n\u001b[1;32m---> 18\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m e\n",
      "File \u001b[1;32mD:\\AMI\\venv\\Lib\\site-packages\\shap\\explainers\\_gpu_tree.py:8\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m_tree\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Tree, feature_perturbation_codes, output_transform_codes\n\u001b[0;32m      7\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m----> 8\u001b[0m     \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m _cext_gpu\n\u001b[0;32m      9\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mImportError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m     10\u001b[0m     record_import_error(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcext_gpu\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcuda extension was not built during install!\u001b[39m\u001b[38;5;124m\"\u001b[39m, e)\n",
      "\u001b[1;31mImportError\u001b[0m: cannot import name '_cext_gpu' from partially initialized module 'shap' (most likely due to a circular import) (D:\\AMI\\venv\\Lib\\site-packages\\shap\\__init__.py)"
     ]
    }
   ],
   "source": [
    "e = GPUTreeExplainer(model_xgb)\n",
    "e.shap_values(X_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3e2baf75-5bb3-43a3-81eb-e64138dc2ba6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
